import '../../scss/login.scss';
import $ from '../jquery-3.4.1.min.js';
// import ajax from '../utils/ajax.js';//别开！！！
var phone;//手机号
var regiphone = /^1[3-9]\d{9}$/;
var regpass = /^[A-Z][[a-zA-Z0-9]{5,15}/;
var password;//密码
let phonemsg;
console.log(phonemsg);
$("#four-ipt").on('blur', '#your-phone', function () {//手机号
    phone = $('#your-phone').val();
    if (!regiphone.test(phone)) {
        $("#your-phone").css("border", "1px solid red");
        $("#phone-msg").text("请输入正确的密码格式-/^1[3-9]\d{9}$/");
        phonemsg = $("#phone-msg").text();
    } else {
        $("#your-phone").css("border", "1px solid #ccc");
        $("#phone-msg").text("");
        phonemsg = $("#phone-msg").text();
    }
})
let passmsg;
$("#four-ipt").on('blur', '#your-password', function () {//密码
    password = $('#your-password').val();
    if (!regpass.test(password)) {
        $("#your-password").css("border", "1px solid red");
        $("#password-msg").text("请输入正确的密码格式-/^[A-Z][[a-zA-Z0-9]{5,15}/");
        passmsg = $("#password-msg").text();
    } else {
        $("#your-password").css("border", "1px solid #ccc");
        $("#password-msg").text("");
        passmsg = $("#password-msg").text();
    }
})
$("#register-button").on('click', 'button', function () {//登录
    if (phonemsg == '' && passmsg == '') {
        $.ajax({
            url: 'http://localhost:3100/pjw-user/dlyonghu',
            type: 'POST',
            data: {
                phone, password
            },
            success(res) {
                console.log('后端操控结果:', res);
                if (res.code == 200) {
                    localStorage.token = res.token;//勿删
                    alert('成功');
                    location.href = '../../index.html';
                } else {
                    alert('失败');
                }
            }
        })
    } else {
        alert('请重新登录');
    }
})